import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '编码',
    align:"center",
    sorter: true,
    width: '100px',
    dataIndex: 'warehouseCode'
   },
   {
    title: '名称',
    align:"center",
    dataIndex: 'warehouseName'
   },
   {
    title: '存储类型',
    align:"center",
    dataIndex: 'storageType',
    width: '100px',
    customRender: ({ text }) => {
      return render.renderDict(text, 'storage_type');
    },
   },
   {
    title: '存储属性',
    align:"center",
    dataIndex: 'locationAttribute',
    width: '100px',
    customRender: ({ text }) => {
      return render.renderDict(text, 'location_attribute');
    },
   },
   {
    title: '归属部门',
    align:"center",
    width: '120px',
    dataIndex: 'departmentName'
   },
   {
    title: '归属部门编号',
    align:"center",
    width: '120px',
    dataIndex: 'departmentCode',
    ifShow:false
   },
   {
    title: '归属部门ID',
    align:"center",
    dataIndex: 'departmentId',
    ifShow:false
   },
   {
    title: '联系人',
    align:"center",
    width: '100px',
    dataIndex: 'contactPerson'
   },
   {
    title: '联系电话',
    align:"center",
    width: '100px',
    dataIndex: 'contactNumber'
   },
   {
    title: '地址',
    align:"center",
    dataIndex: 'warehouseAddress'
   },
   {
    title: '允许负库存',
    align:"center",
    width: '110px',
    dataIndex: 'isNegativeInventory',
    customRender:({text}) => {
       return  render.renderSwitch(text, [{text:'是',value:'1'},{text:'否',value:'0'}])
     },
   },
   {
    title: '盘点冻结',
    align:"center",
    width: '100px',
    dataIndex: 'isInventoryFreezing',
    customRender:({text}) => {
       return  render.renderSwitch(text, [{text:'是',value:'1'},{text:'否',value:'0'}])
     },
   },
   {
    title: '库位管理',
    align:"center",
    width: '100px',
    dataIndex: 'isIocationManagement',
    customRender:({text}) => {
       return  render.renderSwitch(text, [{text:'是',value:'1'},{text:'否',value:'0'}])
     },
   },
   {
    title: '批号管理',
    align:"center",
    width: '100px',
    dataIndex: 'isNumberManagement',
    customRender:({text}) => {
       return  render.renderSwitch(text, [{text:'是',value:'1'},{text:'否',value:'0'}])
     },
   },
   {
    title: '第三方编码',
    align:"center",
    width: '110px',
    dataIndex: 'thirdPartyCode'
   }
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "名称",
    field: 'warehouseName',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "存储属性",
    field: 'locationAttribute',
    component: 'JDictSelectTag',
    colProps: { span: 6 },
    componentProps: {
      dictCode: "location_attribute"
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '编码',
    field: 'warehouseCode',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
  },
  {
    label: '名称',
    field: 'warehouseName',
    component: 'Input',
  },
  {
    label: '存储类型',
    field: 'storageType',
    component: 'JDictSelectTag',
    defaultValue: 0,
    componentProps:{
        dictCode:"storage_type",
        stringToNumber: true,
     },
  },
  {
    label: '存储属性',
    field: 'locationAttribute',
    component: 'JDictSelectTag',
    defaultValue:0,
    componentProps:{
        dictCode:"location_attribute",
        stringToNumber: true,
     },
    dynamicRules: () => {
      return [ { required: true, message: '请选择属性!'} ];
     },
  },
  {
    label: '归属部门',
    field: 'departmentName',
    component: 'JSelectDept',
    componentProps:({})=>{
      return{
        multiple: false,
        showButton:false,
        checkable:false,
        labelKey: 'departName'
      }
    },
  },
  {
    label: '归属部门编号',
    field: 'departmentCode',
    component: 'Input',
    show:false
  },
  {
    label: '归属部门ID',
    field: 'departmentId',
    component: 'Input',
    show:false
  },
  {
    label: '联系人',
    field: 'contactPerson',
    component: 'Input',
    slot: 'stockUnitSlot',
  },
  {
    label: '联系电话',
    field: 'contactNumber',
    component: 'Input',
    rules: rules.rule('phone', false),
  },
  {
    label: '地址',
    field: 'warehouseAddress',
    component: 'Input',
  },
  {
    label: '允许负库存',
    field: 'isNegativeInventory',
    defaultValue: 0,
     component: 'JSwitch',
     componentProps:{
         options:[1,0]
     },
  },
  {
    label: '盘点冻结',
    field: 'isInventoryFreezing',
    defaultValue: 0,
     component: 'JSwitch',
     componentProps:{
         options:[1,0]
     },
  },
  {
    label: '库位管理',
    field: 'isIocationManagement',
    defaultValue: 0,
     component: 'JSwitch',
     componentProps:{
         options:[1,0]
     },
  },
  {
    label: '批号管理',
    field: 'isNumberManagement',
    defaultValue: 0,
     component: 'JSwitch',
     componentProps:{
         options:[1,0]
     },
  },
  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input',
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}